'use strict';

const Service = require('egg').Service;

class AdminService extends Service {
  async userlogin(body) {
    try {
      return await this.ctx.model.User.findOne({
        where: { account: body.username, password: this.ctx.helper.md5(body.password), status: 1 },
        include: [
          { model: this.ctx.model.Roleresource, attributes: [[ 'resource_array', 'resourceArray' ]] },
          { model: this.ctx.model.Role, attributes: [[ 'isAdmin', 'isAdmin' ]] }
        ],
        raw: true,
      });
    } catch (e) {
      return e.message;
    }
  //  const user = await this.ctx.db.query('select * from user where uid = ?', uid);
  //  return user;
  }
}

module.exports = AdminService;
